package com.vito.oa.email.impl;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.vito.base.authoriza.model.UserModel;
import com.vito.oa.email.contact.dao.ExternalContactsMapper;
import com.vito.oa.email.contact.dao.OaBaseUserMapper;
import com.vito.oa.email.contact.dao.OaJamesUserMapper;
import com.vito.oa.email.model.OaEmailContant;
import com.vito.oa.email.model.OaJamesUser;
import com.vito.oa.email.service.OaEmailService;

@Service
public class OaEmailServiceImpl implements OaEmailService {
	
	private static final Logger log = LoggerFactory.getLogger(OaEmailServiceImpl.class);
	
	@Autowired
	private OaJamesUserMapper oaJamesUserMapper;
	
	@Autowired 
	private OaBaseUserMapper oaBaseUserMapper;
	
	@Autowired 
	private ExternalContactsMapper contactsMapper;

	public boolean saveUserMail(OaJamesUser jamesUser, UserModel user) {
		boolean b = false;
		try {
			b = oaJamesUserMapper.addOaJamesUser(jamesUser) > 0;
			if (!b) {
				log.error("注册邮件服务器账号失败");
			}
		} catch (Exception e) {
			log.error("注册邮件服务器账号失败" + e);
		}
		b = oaBaseUserMapper.updateUserEmail(user)> 0;
		if (!b) {
			log.error("修改用户邮箱账号失败");
		}
		return b;
	}

	public boolean addOaJamesUser(OaJamesUser jamesUser) {
		jamesUser.setPasswordHashAlgorithm(OaEmailContant.PASSWORD_HASH_ALGORITHM);
		jamesUser.setVersion(OaEmailContant.VERSION);
		return oaJamesUserMapper.addOaJamesUser(jamesUser) > 0;
	}

	public boolean updateJamesUserPassWord(String passWord, String userName) {
		
		return oaJamesUserMapper.updateJamesUserPassWord(passWord,userName);
	}

}
